﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;

namespace AutomationAdmin.ViewModels
{
    public class ReqStatusColorConverter : IValueConverter
    {
        public object Convert(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            NewAppRequest.ReqStatus status = (NewAppRequest.ReqStatus)value;
            RadialGradientBrush brush;
            switch (status)
            {
                case NewAppRequest.ReqStatus.Completed:
                    brush = new RadialGradientBrush(Colors.Green, Colors.Transparent);
                    break;
                case NewAppRequest.ReqStatus.Cancelled:
                    brush = new RadialGradientBrush(Colors.LightGray, Colors.Transparent);
                    break;
                case NewAppRequest.ReqStatus.Halted:
                    brush = new RadialGradientBrush(Colors.Red, Colors.Transparent);
                    break;
                case NewAppRequest.ReqStatus.InProgress:
                    brush = new RadialGradientBrush(Colors.Yellow, Colors.Transparent);
                    break;
                case NewAppRequest.ReqStatus.NotStarted:
                    brush = new RadialGradientBrush(Colors.LightGray, Colors.Transparent);
                    break;
                default:
                    brush = new RadialGradientBrush(Colors.LightGray, Colors.Transparent);
                    break;
            }

            brush.Center = new Point(0, 1.5);
            brush.GradientOrigin = new Point(0.5, -1.5);
            brush.RadiusX = 3;
            brush.RadiusY = 3;
            return brush;
        }

        public object ConvertBack(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            Color color = (Color)value;

            if (color == Colors.Green)
            {
                return NewAppRequest.ReqStatus.Completed;
            }

            if (color == Colors.LightGray)
            {
                return NewAppRequest.ReqStatus.Cancelled;
            }

            if (color == Colors.Red)
            {
                return NewAppRequest.ReqStatus.Halted;
            }

            if (color == Colors.Yellow)
            {
                return NewAppRequest.ReqStatus.InProgress;
            }

            if (color == Colors.LightGray)
            {
                return NewAppRequest.ReqStatus.NotStarted;
            }

            return Colors.Transparent;
        }
    }
}
